package org.example.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.http.server.RequestPath;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

/**
 * @author TonySong
 * @date 2024/5/6 0006
 * @time 16:16
 */
@Component
@Slf4j
public class LogFilter  implements GlobalFilter {
    @Override
    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
        log.info("LogFilter");
        log.info("全局过滤器的请求路径为：{}", exchange.getRequest().getURI().getPath());
        //业务操作
        RequestPath path = exchange.getRequest().getPath();

        if(path.equals("/test1")) {
            return chain.filter(exchange);
        }else{
            log.info("请求路径错误，终止访问！");
            return null;
        }
    }
}
